package com.cmower.dzone.stopdoing3things;

import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * @author 沉默王二，一枚有趣的程序员
 */
public class Null2OptionalDemo {
    public static void main(String[] args) {
        Optional<List<String>> list = getNamesFromDB();
list.ifPresent(names -> {
    for (String name : names) {
        System.out.println(name);
    }
});
    }

    public static Optional<List<String>> getNamesFromDB() {
        boolean hasName = true;
        if (hasName) {
            String [] names = {"沉默王二", "一枚有趣的程序员"};
            return Optional.of(null);
        }
        return Optional.empty();
    }
}

